import 'package:baselib/utils/image_util.dart';
import 'package:baselib/widgets/comm_app_bar.dart';
import 'package:baselib/widgets/comm_password_textfield.dart';
import 'package:baselib/widgets/comm_textfield.dart';
import 'package:baselib/widgets/gradient_card_view.dart';
import 'package:baselib/widgets/gradient_text_widget.dart';
import 'package:baselib/widgets/inkwell_button.dart';
import 'package:baselib/widgets/nosize_app_bar.dart';
import 'package:baselib/widgets/simple_button.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:framelib/utils/color_util.dart';
import 'package:framelib/utils/drawable_util.dart';
import 'package:framelib/utils/px_util.dart';
import 'package:framelib/utils/string_util.dart';
import 'package:framelib/widgets/main_gradient_button.dart';
import 'package:framelib/widgets/page_widget.dart';
import 'package:get/get.dart';
import 'package:module_business/module_comm/viewmodel/login_email_view_model.dart';
/**
 * 登录主页
 */
class LoginEmailPage extends GetWidget<LoginEmailViewModel> {
  @override
  Widget build(BuildContext context) {
    return PageWidget.build(
        builder: (LoginEmailViewModel model){
          return PageWidget.PageScaffoldWidget(
            isShowBg: true,
            appBar: CommAppBar(
              // isBarStatusWhite: false,
              backgroundColor: ColorUtil.instance.color_transparent,
              // elevation: PxUtil.instance.px_0,
            ),
            body: Container(
                width: PxUtil.instance.screenWidth,
                // height: PxUtil.instance.screenHeight-PxUtil.instance.statusBarHeight-
                //   PxUtil.instance.bottomBarHeight,
                padding: EdgeInsets.only(
                  left: PxUtil.instance.px_15,
                  right: PxUtil.instance.px_15,
                ),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    SizedBox(height: PxUtil.instance.px_26,),
                    ImagesUtil.loadAssetImage(
                        DrawableUtil.instance.icon_login,
                        height: PxUtil.instance.px_24,
                        fit: BoxFit.fitHeight
                    ),
                    SizedBox(height: PxUtil.instance.px_12,),
                    //标题
                    Text(
                      '${StringUtil.instance.To_a_mailbox}',
                      style: TextStyle(
                          color: ColorUtil.instance.color_white,
                          fontSize: PxUtil.instance.px_12
                      ),
                    ),
                    Expanded(child: _buildMiddleContUi(model)),
                    //点击用户协议
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        InkWellButton(
                          onPressed: ()=>model?.selectAgreement(),
                          child: Container(
                            margin: EdgeInsets.only(
                              // bottom: PxUtils.px_2
                            ),
                            child: Obx(()=>ImagesUtil.loadAssetImage(
                                model?.isAgreementSelected.value?
                                DrawableUtil.instance.icon_selected:DrawableUtil.instance.icon_unselected,
                                width: PxUtil.instance.px_20
                            )),
                          ),
                        ),
                        SizedBox(
                          width: PxUtil.instance.px_15,
                        ),
                        InkWellButton(
                          onPressed: ()=>model.toTermsOfService(),
                          child: Text(
                            '${StringUtil.instance.Terms_of_Service}',
                            style: TextStyle(
                                fontSize: PxUtil.instance.px_12,
                                color: ColorUtil.instance.color_white
                            ),
                          ),
                        ),
                        Text(
                          ' ${StringUtil.instance.he} ',
                          style: TextStyle(
                              fontSize: PxUtil.instance.px_13,
                              color: ColorUtil.instance.color_8927ED
                          ),
                        ),
                        InkWellButton(
                          onPressed: ()=>model.toPrivacyPolicy(),
                          child: Text(
                            '${StringUtil.instance.Privacy_Policy}',
                            style: TextStyle(
                                fontSize: PxUtil.instance.px_12,
                                color: ColorUtil.instance.color_white
                            ),
                          ),
                        ),
                      ],
                    ),
                    SizedBox(
                      height: PxUtil.instance.px_15,
                    ),
                  ],
                ),
              ),
          );
        }
    );
  }

  _buildMiddleContUi(LoginEmailViewModel model) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        //账号
        GradientCardView(
          margin: EdgeInsets.only(
            top: PxUtil.instance.px_26,
          ),
          padding: EdgeInsets.only(
            left: PxUtil.instance.px_15,
            right: PxUtil.instance.px_15,
          ),
          height: PxUtil.instance.px_43,
          backGroundColor: ColorUtil.instance.color_2F3F71,
          child: Row(
            children: [
              Container(
                margin: EdgeInsets.only(
                    right: PxUtil.instance.px_15
                ),
                child: ImagesUtil.loadAssetImage(
                    DrawableUtil.instance.icon_login_email,
                    height: PxUtil.instance.px_16,
                  fit: BoxFit.fitHeight
                ),
              ),
              Expanded(child: CommTextField(
                key: Key('${DateTime.now().millisecondsSinceEpoch}'),
                defaultUnderlineColor: ColorUtil.instance.color_transparent,
                foucosUnderlineColor: ColorUtil.instance.color_transparent,
                lableText: StringUtil.instance.Please_enter_your_account_number,
                lableTextStyle: TextStyle(fontSize: PxUtil.instance.px_14,
                    color: ColorUtil.instance.color_878787),
                textStyle: TextStyle(fontSize: PxUtil.instance.px_14,
                    color: ColorUtil.instance.color_white),
                paddingBottm: PxUtil.instance.px_4,
                inputFormatters: [FilteringTextInputFormatter.allow(RegExp("[0-9a-zA-Z._@]"))],
                // keyboardType: TextInputType.phone,
                isShowDeleteMain: true,
                maxLength: 20,
                maxLines: 1,
                defaultCont: model?.account??'',
                textInputAction: TextInputAction.next,
                onChanged: (value)=>model?.inputChanged(value,0),
              ))
            ],
          )
        ),
        GradientCardView(
            margin: EdgeInsets.only(
              top: PxUtil.instance.px_26,
            ),
            padding: EdgeInsets.only(
              left: PxUtil.instance.px_15,
              right: PxUtil.instance.px_15,
            ),
            height: PxUtil.instance.px_43,
            backGroundColor: ColorUtil.instance.color_2F3F71,
            child: Row(
              children: [
                Container(
                  margin: EdgeInsets.only(
                      left: PxUtil.instance.px_3,
                      right: PxUtil.instance.px_19
                  ),
                  child: ImagesUtil.loadAssetImage(
                      DrawableUtil.instance.icon_login_lock,
                      height: PxUtil.instance.px_16,
                    fit: BoxFit.fitHeight
                  ),
                ),
                Expanded(child: CommPasswordTextField(
                  defaultUnderlineColor: ColorUtil.instance.color_transparent,
                  foucosUnderlineColor: ColorUtil.instance.color_transparent,
                  lableText: StringUtil.instance.Please_enter_your_password,
                  lableTextStyle: TextStyle(fontSize: PxUtil.instance.px_14,color: ColorUtil.instance.color_878787),
                  textStyle: TextStyle(fontSize: PxUtil.instance.px_14,color: ColorUtil.instance.color_white),
                  paddingBottm: PxUtil.instance.px_4,
                  isShowEye: true,
                  defaultCont: model?.password??'',
                  maxLength: 20,
                  maxLines: 1,
                  inputFormatters: [FilteringTextInputFormatter.allow(RegExp("[0-9A-Za-z,.@]"))],
                  onChanged: (value)=>model?.inputChanged(value,1),
                ))
              ],
            )
        ),
        SizedBox(height: PxUtil.instance.px_12,),
        //Forget the password       Register
        Row(
          children: [
            SizedBox(width: PxUtil.instance.px_10,),
            InkWellButton(
              onPressed: ()=>model.toForgetPasswordPage(),
              child: GradientTextWidget(
                txt: StringUtil.instance.Forget_the_password,
              ),
            ),
            Expanded(child: Container()),
            InkWellButton(
              onPressed: ()=>model.toRegister(),
              child: GradientTextWidget(
                txt: StringUtil.instance.Register,
              ),
            ),
            SizedBox(width: PxUtil.instance.px_10,),
          ],
        ),
        //登录
        Container(
          margin: EdgeInsets.only(
              top: PxUtil.instance.px_35,
          ),
          child: MainGradientButton(
            onPressed: ()=>model.login(),
            isImg: true,
            imgPath: DrawableUtil.instance.icon_Log_In,
            imgWidth: PxUtil.instance.px_53,
          ),
        ),


      ],
    );
  }

}
